/*
 * @Author: your name
 * @Date: 2021-01-06 11:41:34
 * @LastEditTime: 2021-02-18 23:11:12
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \express-seed\dao\imgDao.js
 */
const { querySql } = require('../db')
module.exports = {
    // 查询图片列表
    async selectImgsDao(id) {
        const sql = !id ? `select * from imgs` : `select img_path from imgs where id='${id}'`
        return await querySql(sql)
    },
    //添加图片列表
    async addImgDao(imgsInfo) {
        let insertStr = ''
        imgsInfo.forEach(item => {
            insertStr += `('${item.name}','${item.imgPath}'),`
        })
        let sql = `insert into imgs (img_name, img_path) values ` + insertStr
        sql = sql.substr(0, sql.length - 1)
        return await querySql(sql)
    },
    //添加项目工程图片
    /**
     * @description: 
     * @param {*} imgsInfo //图片信息集合
     * @param {*} pid //project_code表的id
     * @return {Promise}
     */
    async addProjectImgDao(imgsInfo,pid) {
        let insertStr = ''
        imgsInfo.forEach(item => {
            insertStr += `('${item.name}','${item.imgPath}','${pid}'),`
        })
        let sql = `insert into project_code_imgs (img_name, img_path , pid) values ` + insertStr
        sql = sql.substr(0, sql.length - 1)
        return await querySql(sql)
    },
    //根据id删除图片
    async delImgDao(img_id) {
        const sql = `delete from imgs where id='${img_id}'`
        return await querySql(sql)
    }
}